package com.wuye.web.house.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuye.web.house.entity.HouseBuild;
import com.wuye.web.house.entity.HouseBuildParam;
import com.wuye.web.house.mapper.HouseBuildMapper;
import com.wuye.web.house.service.IHouseBuildService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 楼栋表 服务实现类
 * </p>
 *
 * @author 孤筏
 * @since 2023-07-28
 */
@Service
public class HouseBuildServiceImpl extends ServiceImpl<HouseBuildMapper, HouseBuild> implements IHouseBuildService {

    @Override
    public IPage<HouseBuild> getHouseBulidList(HouseBuildParam houseBuildParam) {
        //创建分页对象
        IPage<HouseBuild> page = new Page<>(houseBuildParam.getCurrentPage(),houseBuildParam.getPageSize());
        //获取名字和类型
        String buildName = houseBuildParam.getBuildName();
        Integer type = houseBuildParam.getType();

        //构建查询条件
        LambdaQueryWrapper<HouseBuild> queryWrapper = new LambdaQueryWrapper<>();
        if (!Objects.isNull(buildName)){
            queryWrapper.like(HouseBuild::getBuildName,buildName);
        }
        if (!Objects.isNull(type)){
            queryWrapper.eq(HouseBuild::getType,type);
        }

        return this.baseMapper.selectPage(page,queryWrapper);
    }
}
